//
//  ZGLNewChannelVC.m
//  Faker
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZGLNewChannelVC.h"
#import "ZGLAddNewChannelCell.h"
#import <UIImageView+AFNetworking.h>

@interface ZGLNewChannelVC () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *addNewChannelTableView;


@end

@implementation ZGLNewChannelVC

- (void)dealloc {
    _addNewChannelTableView.delegate = nil;
    _addNewChannelTableView.dataSource = nil;
}

#pragma mark - setSearchBar
- (void)setNaviBar {
    self.title = @"本周新上线频道";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"AmericanTypewriter-Bold" size:20], NSFontAttributeName, nil]];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zaihufanhui"] style:(UIBarButtonItemStyleDone) target:self action:@selector(leftBarButtonItem:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)leftBarButtonItem:(UIBarButtonItem *)button {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)createTableView {
    self.addNewChannelTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScaleX * 375, ScaleY * 667 + 49) style:(UITableViewStyleGrouped)];
    [self.view addSubview:self.addNewChannelTableView];
    self.addNewChannelTableView.delegate = self;
    self.addNewChannelTableView.dataSource = self;
    [self.addNewChannelTableView registerClass:[ZGLAddNewChannelCell class] forCellReuseIdentifier:@"ZGLNewChannelVC_ZGLAddNewChannelCell"];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNaviBar];
    [self createTableView];
    // Do any additional setup after loading the view.
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.modelArr.count == 0) {
        return 3;
    } else {
        return self.modelArr.count;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZGLAddNewChannelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZGLNewChannelVC_ZGLAddNewChannelCell"];
    cell.searchModel = self.modelArr[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return ScaleY * 80;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return ScaleY *  120;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScaleX * 375, ScaleY *  80)];
    headView.backgroundColor = [UIColor whiteColor];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScaleX * 20, ScaleY *10, ScaleX * 335, ScaleY * 60)];
    [imageView setImageWithURL:[NSURL URLWithString:@"http://zkres.myzaker.com/201510/aHR0cDovL3VwbG9hZC5teXpha2VyLmNvbS9kYXRhL2FwcF9pbmZvLzIwMTUtMTAtMjMvMTQ0NTU2NjM0ODExNzcucG5n_10000.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    [headView addSubview:imageView];
    return headView;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
